#coding:utf-8
'''
Created on 2017-04-20

@author: sandy
'''

import os
import json
import logging
from pycommon import Utils
from pycommon import RemoteManager

class Config(object):
    
    def __init__(self):
        self.rundir = os.path.dirname(__file__)
        self.game_db_name = u""
        self.game_db_host = u"127.0.0.1"
        self.game_db_port = 3306
        self.game_db_user = u"root"
        self.game_db_passwd = u"1111"
        self.game_db_linkcount = 2


        self.log_ip = u"127.0.0.1"
        self.log_port = 1240      
        
        self.web_ip = u"127.0.0.1"
        self.web_port = 8023

        self.center_ip = u"127.0.0.1"
        self.center_port = 0

    
    def onRemoteConfig(self, cfgname, jf):
        ctype,cname = cfgname.split(u".")
        if ctype==u'server'+unicode(RemoteManager.instance.sid) and cname==u'serverconfig':
            self.loadFromJson(jf)
       
    def loadFromJson(self, cf):
        logging.debug(u"billserver parse serverconfig.json")
        dbstr = cf.get("game_dbe")
        if dbstr==None:
            dbstr = cf.get("game_db")
        else:
            dbstr = Utils.dencryptDbStr(dbstr)
        dbparams = dbstr.split(u',')
        self.game_db_name = dbparams[2]
        self.game_db_host = dbparams[0]
        self.game_db_port = int(dbparams[1])
        self.game_db_user = dbparams[3]
        self.game_db_passwd = dbparams[4]
        self.game_db_linkcount = int(dbparams[5]) 

        self.log_ip = cf.get("log_ip")
        self.log_port = cf.get("log_port")
        self.web_ip = cf.get("web_ip")
        self.web_port = cf.get("web_port")

        self.center_ip = cf.get("center_ip")
        self.center_port = cf.get("center_port")
   
instance = Config()